package com.zzh.bridge;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import com.zzh.bridge.BridgeIntent;

import org.jetbrains.annotations.NotNull;

public abstract class Bridge {

    protected static final String TAG = BridgeIntent.TAG;

    /**
     * 分发
     *
     * @param pageType
     * @param context
     * @param bundle
     * @param requestCode
     */
    public abstract void start(@NotNull String pageType, @NotNull Context context, Bundle bundle, int requestCode);

    /**
     * 跳转
     *
     * @param cls
     * @param context
     * @param bundle
     * @param requestCode
     * @param <T>
     */
    protected <T extends Activity> void startActivity(@NotNull Class<T> cls, @NotNull Context context, Bundle bundle, int requestCode) {
        android.content.Intent intent = new android.content.Intent(context, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        if (requestCode > 0 && context instanceof Activity) {
            ((Activity) context).startActivityForResult(intent, requestCode);
            return;
        }
        context.startActivity(intent);
    }

    /**
     * 获取标识
     *
     * @return
     */
    public abstract String getName();


    public abstract Class get(@NotNull String pageType);



}
